Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.3
Session state in web services

In some cases login status may be lost between different calls to a web service. The reason of such behavior does not depend on Sitecore, as a valid session id cookie is not generated by the web service layer until the Session object is actually used.

You can observe the behavior described by following the steps below:

  1. Create a web service with two methods: Login and GetCurrentUser. Login should call Domain.Login and GetCurrentUser should return Domian.CurrentUser. Remember to EnableSession on the methods. 
  2. Create a Windows application (not just a web page) that calls the two methods (Login first). Remember to use a CookieContainer.
  3. GetCurrentUser will return null. If you debug, the Login and GetCurrentUser methods will have different Session.SessionID.
  4. Add the line: Session["dummy"] = "dummy" to the Login method and re-run the test.
  5. GetCurrentUser will now return the correct user, and if you debug, the Login and GetCurrentUser methods will have the same Session.SessionID.